package com.tr.rentcar.model;

import java.util.List;

/**
 * 分页对象
 * @author gson
 *
 * @param <T>
 */
public class Pager<T> {

	/**
	 * 当前页码
	 */
	private Integer page = 1;

	/**
	 * 页大小
	 */
	private Integer pageSize = 10;

	/**
	 * 当前页的数据
	 */
	private List<T> rows;

	/**
	 * 总记录数
	 */
	private Long total;

	/**
	 * 总页数
	 */
	private Integer totalPage;

	public Pager(Integer page) {
		this.page = page;
	}

	public Pager(Integer page, Integer pageSize) {
		this.page = page;
		this.pageSize = pageSize;
	}
	
	/**
	 * 获取分页参数
	 * @return
	 */
	public int getStart() {
		return (this.page - 1) * this.pageSize;
	}

	public Integer getPage() {
		return page;
	}

	public void setPage(Integer page) {
		this.page = Math.max(page, 1);
	}

	public List<T> getRows() {
		return rows;
	}

	public void setRows(List<T> rows) {
		this.rows = rows;
	}

	public Long getTotal() {
		return total;
	}

	public void setTotal(Long total) {
		this.total = total;
	}

	public Integer getTotalPage() {
		return (int) Math.ceil(total / pageSize);
	}

	public void setTotalPage(Integer totalPage) {
		this.totalPage = totalPage;
	}

	public void setPageSize(Integer pageSize) {
		this.pageSize = pageSize;
	}

	public Integer getPageSize() {
		return pageSize;
	}

	@Override
	public String toString() {
		return "Pager [page=" + page + ", pageSize=" + pageSize + ", rows=" + rows + ", total=" + total + ", totalPage="
				+ totalPage + "]";
	}

	
}
